//
//  LYSystemMessageController.m
//  SelectCity
//
//  Created by liuyan on 2019/3/20.
//  Copyright © 2019年 liuyan. All rights reserved.
//

#import "LYSystemMessageController.h"
#import "LYSystemMessageModel.h"
#import "LYSystemMessageCell.h"

@interface LYSystemMessageController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableview;
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation LYSystemMessageController

- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
        NSArray *array = @[
                           @{@"name":@"简历审核通",@"detail":@"亲爱的”李晓明“m，你的简历发布成功，来开启您的求职之旅吧"},
                           @{@"name":@"注册成功",@"detail":@"亲爱的”李晓明“m，恭喜您来到特聘网",@"other":@"查看最新职位",@"url":@"http://www.baidu.com"}
                           ];
        for (NSDictionary *dic in array) {
            LYSystemMessageModel *model = [LYSystemMessageModel mj_objectWithKeyValues:dic];
            model.textheight = [model.detail sizeOfFont:[UIFont systemFontOfSize:13] maxSize:CGSizeMake(WIDTH - 25, 0)].height;
            if (model.other.length) {
               model.cellheight = model.textheight + 60 + 31;
            }else{
                model.cellheight = model.textheight + 60;
            }
            [_dataArray addObject:model];
        }
    }
    return _dataArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"官方通知";
    
    [self initUI];
}
- (void)initUI {
    self.tableview = [UIToolsControl initTableViewWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-HeightOfStatusBarAndNavigationBar-SIMEmojKeyBoardkBottomNOSafeArea_Height) target:self style:UITableViewStyleGrouped];
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.tableview registerClass:[LYSystemMessageCell class] forCellReuseIdentifier:kCellIdentifier_LYSystemMessageCell];
    [self.view addSubview:self.tableview];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LYSystemMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_LYSystemMessageCell forIndexPath:indexPath];
    cell.model = self.dataArray[indexPath.section];
    return cell;
}
#pragma mark -- UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    LYSystemMessageModel *model = self.dataArray[indexPath.section];
    return model.cellheight;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 30*Scale)];
    label.backgroundColor = [UIColor clearColor];
    label.textColor = THEMECOLOR_OF_TEXT_9a9a9a;
    label.textAlignment = NSTextAlignmentCenter;
    label.text = @"2018-03-21 12:30";
    label.font = Font(Font_13);
    return label;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 30*Scale;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.001f;
}

@end
